package com.it.labservice.repository;

import com.it.labservice.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface UserRepository extends JpaRepository<User, Long> {
    User findByUsername(String username);
    List<User> findByRole(User.UserRole role);
    long countByRole(User.UserRole role);
    
    @Query("SELECT u FROM User u LEFT JOIN FETCH u.laboratories WHERE u.id = :id")
    Optional<User> findByIdWithLaboratories(@Param("id") Long id);
} 